<template>
	<view class="index">
		<view class="search-bar">
			<view class="date">
				<picker mode="date" :value="startDate" @change="changeDateByDay">
					<text>{{startDate}}</text>
					<uni-icons type="calendar-filled" class="icon" color="#ffffff" size="18"></uni-icons>
				</picker>
			</view>
			<view class="misc">
				{{ miscStr(startDate) }}
			</view>
		</view>
		<view class="content-wrapper">
			<view class="title-wrapper">
				<view class="title">
					统计分析
				</view>
			</view>
			<view class="statistics-wrapper">
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.salesAmount }}</text>
						<text class="unit">元</text>
					</view>
					<view class="label">
						货款
					</view>
				</view>
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.salesVolume }}</text>
						<text class="unit">件</text>
					</view>
					<view class="label">
						销售量
					</view>
				</view>
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.grossWeight }}</text>
						<text class="unit">斤</text>
					</view>
					<view class="label">
						毛重
					</view>
				</view>
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.netWeight }}</text>
						<text class="unit">斤</text>
					</view>
					<view class="label">
						净重
					</view>
				</view>
			</view>
			<view class="statistics-wrapper margin">
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.serviceFee }}</text>
						<text class="unit">元</text>
					</view>
					<view class="label">
						代采费
					</view>
				</view>
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.freightAmount }}</text>
						<text class="unit">元</text>
					</view>
					<view class="label">
						运费
					</view>
				</view>
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.orderNum }}</text>
						<text class="unit">个</text>
					</view>
					<view class="label">
						订货单
					</view>
				</view>
				<view class="item">
					<view class="number">
						<text>{{ saleStatistics.afterSaleNum }}</text>
						<text class="unit">件</text>
					</view>
					<view class="label">
						售后件数
					</view>
				</view>
			</view>
		</view>
		<view class="content-wrapper">
			<view class="title-wrapper">
				<view class="title">
					经营报表
				</view>
			</view>
			<view class="menu-wrapper">
				<view class="item" @click="goPage('/subPage_report/products')">
					<view class="label">
						商品销售报表
					</view>
					<view class="value">
						<text>各商品的销量及销售额排名统计</text>
						<uni-icons type="right" class="icon" color="#A6A6A6" size="16"></uni-icons>
					</view>
				</view>
				<view class="item" @click="goPage('/subPage_report/customer')">
					<view class="label">
						客户销售报表
					</view>
					<view class="value">
						<text>各客户的销量及销售额排名统计</text>
						<uni-icons type="right" class="icon" color="#A6A6A6" size="16"></uni-icons>
					</view>
				</view>
				<view class="item" @click="goPage('/subPage_report/afterSale')">
					<view class="label">
						商品售后报表
					</view>
					<view class="value">
						<text>各商品的售后排名统计</text>
						<uni-icons type="right" class="icon" color="#A6A6A6" size="16"></uni-icons>
					</view>
				</view>
			</view>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				startDate: this.$helper.getDay(0, '-'),
				end: this.$helper.getDay(1, '-'),
				saleStatistics: {
					afterSaleNum: 0,
					grossWeight: 0,
					orderNum: 0,
					salesAmount: 0,
					salesVolume: 0,
					serviceFee: 0,
					netWeight: 0,
					freightAmount: 0
				}
			}
		},
		mounted() {
			this.getServerData();
		},
		methods: {
			async getServerData() {
				const data = await this.$api.post('/app/statistic/pickupPointStatistic', {
					queryDay: this.startDate,
					pickupPointId: this.$store.state.userInfo.pickupPointId,
				})
				if (data.data) {
					this.saleStatistics.afterSaleNum = data.data.afterSaleNum || 0;
					this.saleStatistics.grossWeight = data.data.grossWeight || 0;
					this.saleStatistics.orderNum = data.data.orderNum || 0;
					this.saleStatistics.salesAmount = data.data.salesAmount || 0;
					this.saleStatistics.salesVolume = data.data.salesVolume || 0;
					this.saleStatistics.serviceFee = data.data.serviceFee || 0;
					this.saleStatistics.netWeight = data.data.netWeight || 0;
					this.saleStatistics.freightAmount = data.data.freightAmount || 0;
				}
			},
			changeDateByDay(e) {
				this.startDate = e.detail.value;
				this.getServerData();
			},
			miscStr(date) {
				let str = '';
				let preDate = new Date(date)
				preDate.setDate(preDate.getDate() - 1)
				preDate = preDate.getDate();
				if (preDate < 10) {
					preDate = '0' + preDate;
				}
				const day = date.substring(8, 10)
				str = `${preDate}日12点~${day}日12点下单`
				return str;
			},
			goPage(url) {
				uni.navigateTo({
					url: url
				})
			}
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		background-color: #363F4E;
		padding: 0 20upx;
		overflow: auto;

		.search-bar {
			height: 80upx;
			display: flex;
			align-items: center;
			color: #ffffff;
			font-size: 28upx;

			.date {
				display: flex;
				align-items: center;

				.icon {
					margin-left: 5upx;
				}
			}

			.misc {
				margin-left: 20rpx;
				font-size: 26rpx;
			}
		}

		.content-wrapper {
			overflow: hidden;
			margin-top: 10upx;
			background-color: #ffffff;
			border-radius: 20upx;
			padding: 10rpx 32upx 42upx 32upx;

			.title-wrapper {
				height: 100rpx;
				display: flex;
				align-items: center;

				.title {
					height: 36rpx;
					padding-left: 20rpx;
					border-left: 10rpx solid #F26022;
					line-height: 36rpx;
					font-size: 34rpx;
					font-weight: bold;
				}
			}

			.statistics-wrapper {
				display: flex;
				align-items: center;

				&.margin {
					margin-top: 40rpx;
				}

				.item {
					flex: 1;
					text-align: center;

					.number {
						font-size: 38rpx;
						font-weight: bold;

						.unit {
							font-size: 22rpx;
							color: #555;
							margin-left: 5rpx;
						}
					}

					.label {
						font-size: 28rpx;
						color: #383838;
						margin-top: 10rpx;
					}
				}
			}


			.column-chart-wrapper {
				margin-top: 30upx;
				height: 500upx;

				.label {
					font-size: 30upx;
					color: #383838;
					margin-bottom: 30upx;
				}

				.chart {
					height: 400upx;
				}
			}

			.menu-wrapper {

				.item {
					height: 104upx;
					border-top: 2upx solid #E5E5E5;
					display: flex;
					align-items: center;

					&:last-child {
						border-bottom: 2upx solid #E5E5E5;
					}

					.label {
						font-size: 30upx;
						color: #383838;
					}

					.value {
						flex: 1;
						display: flex;
						justify-content: flex-end;
						align-items: center;
						font-size: 28upx;
						color: #808080;

						.icon {
							margin-left: 5upx;
							position: relative;
							top: 2upx;
						}
					}
				}
			}
		}
	}
</style>